﻿// Sequin.Sequences.Recommenders.Rule
//
// (c) 2011 Arthur Pitman
//
// Part of the Sequin Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License (Version 2.1) as published by the Free Software Foundation.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License (Version 2.1) along with this library; if not, write to the 
// Free Software Foundation, Inc., 
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
// or see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sequin.Sequences;

namespace Sequin.Sequences.Recommenders
{
	/// <summary>
	/// Represents a recommender rule
	/// </summary>
	public class Rule
	{
		/// <summary>
		/// The left hand side of the rule
		/// </summary>
		public Sequence Left;

		/// <summary>
		/// The right hand side of the rule
		/// </summary>
		public Sequence Right;

		/// <summary>
		/// The support of the rule
		/// </summary>
		public double Support;

		/// <summary>
		/// The support of the left hand side of the rule
		/// </summary>
		public double LeftSupport;

		/// <summary>
		/// The support of the right hand side of the rule
		/// </summary>
		public double RightSupport;

		/// <summary>
		/// The confidence of the rule
		/// </summary>
		public double Confidence;

		/// <summary>
		/// The lift of the rule
		/// </summary>
		public double Lift;

		/// <summary>
		/// The weight of the rule
		/// Typically this will be set to be some combination of support, confidence and lift
		/// </summary>
		public double Weight;	

		/// <summary>
		/// Initializes a new <see cref="Rule"/> instance
		/// </summary>
		/// <param name="left">LHS <see cref="Sequence"/></param>
		/// <param name="right">RHS <see cref="Sequence"/></param>
		/// <param name="support">Support of (LHS and RHS)</param>
		/// <param name="leftSupport">Support of LHS</param>
		/// <param name="rightSupport">Support of RHS</param>
		/// <param name="weight">Weight of the <see cref="Rule"/></param>
		public Rule(Sequence left, Sequence right, double support, double leftSupport, double rightSupport, double weight = 1.0)
		{
			Left = left;
			Right = right;
			Support = support;
			LeftSupport = leftSupport;
			RightSupport = rightSupport;

			Confidence = Support / LeftSupport;
			Lift = Support / (LeftSupport * RightSupport);
			Weight = weight;
		}	
	}
}
